import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/app/user/login',
    name: '登录',
    component: () => import('@/views/app/user/login'),
    hidden: true,
    meta: { title: '登录' }
  },
  {
    path: '/app/user/self',
    name: '我的',
    component: () => import('@/views/app/user/self'),
    hidden: true,
    meta: { title: '我的' }
  },
  {
    path: '/app/user/test',
    name: 'test',
    component: () => import('@/views/app/components/footer'),
    hidden: true,
    meta: { title: 'test' }
  },
  {
    path: '/app/user/register',
    name: '注册',
    component: () => import('@/views/app/user/register'),
    hidden: true,
    meta: { title: '注册' }
  },
  {
    path: '/app/user/forget',
    name: '忘记密码',
    component: () => import('@/views/app/user/forget'),
    hidden: true,
    meta: { title: '忘记密码' }
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/app/index',
    component: () => import('@/views/app/index'),
    hidden: true
  },
  {
    path: '/app/search/index',
    name: 'SearchIndexRouter',
    component: () => import('@/views/app/search/index'),
    hidden: true
  },
]
export const asyncRoutes = [
  {
    path: '/',
    component:Layout,
    redirect: '/dashboard',
    meta: { title: '运营平台', icon: 'el-icon-s-management' },
    children: [
      {
        path: '/dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '数据统计', icon: 'el-icon-s-data' }
      },
      {
        path: '/categoryManage',
        name: 'CategoryManage',
        component: () => import('@/views/category/index'),
        meta: { title: '品类管理', icon: 'el-icon-menu' ,roles:['admin']},
      },
      {
        path: '/sellerManage',
        name: 'SellerManage',
        component: () => import('@/views/seller/index'),
        meta: { title: '商户管理', icon: 'el-icon-user' ,roles:['admin']},
      },
      {
        path: '/shopManage',
        name: 'ShopManage',
        component: () => import('@/views/shop/index'),
        meta: { title: '门店管理', icon: 'el-icon-s-shop' ,roles:['admin']},
      },
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
